/**
 * -----------------------------------
 *  Copyright (c) 2021-2025
 *  All rights reserved, Designed By www.linfengtech.cn
 * 林风社交论坛商业版本请务必保留此注释头信息
 * 商业版授权联系技术客服	 QQ:  3582996245
 * 严禁分享、盗用、转卖源码或非法牟利！
 * 版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.app.controller;

import io.linfeng.common.annotation.NoRepeatSubmit;
import io.linfeng.common.utils.AppPageUtils;
import io.linfeng.common.utils.R;
import io.linfeng.common.utils.Result;
import io.linfeng.common.vo.AppChildrenCommentResponse;
import io.linfeng.common.vo.AppCommentResponse;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.admin.service.CommentService;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.linfeng.modules.app.param.AddThumbsForm;
import io.linfeng.modules.app.param.DelCommentForm;
import io.linfeng.modules.app.service.CommentThumbsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * 
 * APP评论接口
 * @author linfeng
 * @email 2445465217@qq.com
 * @date 2022-01-24 21:29:22
 */
@RestController
@RequestMapping("app/comment")
@Api(tags = "移动端——用户评论")
public class AppCommentController {
    @Autowired
    private CommentService commentService;
    @Autowired
    private CommentThumbsService commentThumbsService;

    /**
     * 评论列表
     */
    @GetMapping("/list")
    @ApiOperation("评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "postId", value = "帖子id", paramType = "query",dataType = "Integer", required = true),
            @ApiImplicitParam(name = "page", value = "分页页码",paramType = "query", dataType = "Integer", required = true)
    })
    public Result<Object> list(@RequestParam("postId")Integer postId, @RequestParam("page")Integer page){
        if(page==1){
            return new Result<>().ok(commentService.getCommentListInCache(postId));
        }
        AppPageUtils pages =commentService.queryCommentPage(postId,page);
        return new Result<>().ok(pages);
    }

    /**
     * 子评论列表
     */
    @GetMapping("/remainComment")
    @ApiOperation("子评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论id", paramType = "query",dataType = "Long", required = true)
    })
    public Result<Object> remainComment(@RequestParam("id")Long id){

        List<AppChildrenCommentResponse> list =commentService.remainComment(id);
        return new Result<>().ok(list);
    }

    /**
     * 单条评论删除
     */
    @Login
    @PostMapping("/del")
    @ApiOperation("单条评论删除")
    public Result del(@RequestBody DelCommentForm request, @ApiIgnore @LoginUser AppUserEntity user){
		commentService.del(request,user);

        return new Result();
    }


    /**
     * 评论区的点赞
     */
    @Login
    @PostMapping("/thumbs")
    @NoRepeatSubmit
    @ApiOperation("评论区的点赞")
    public R thumbs(@RequestBody AddThumbsForm request,@ApiIgnore @LoginUser AppUserEntity user){

        commentThumbsService.addThumbs(request,user);
        return R.ok();
    }

    /**
     * 取消评论区的点赞
     */
    @Login
    @PostMapping("/cancelThumbs")
    @NoRepeatSubmit
    @ApiOperation("取消评论区的点赞")
    public R cancelThumbs(@RequestBody AddThumbsForm request,@ApiIgnore @LoginUser AppUserEntity user){

        commentThumbsService.cancelThumbs(request,user);
        return R.ok();
    }

}
